/**
 *
 */
package com.yishuki.bluewhale.db.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

/**
 * @author yhzhu
 *
 */
@Entity
@Table(name="TBL_USER")
public class User implements Serializable {

	/**
	 *
	 */
	private static final long serialVersionUID = -6218046454523974943L;
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="USER_ID")
	private Long userId;

	@Column(name="USER_NAME", unique=true, nullable=false, length=32)
	private String name;

	@Column(name="PASSWORD", nullable=false, length=16)
	private String password;

	@Column(name="EMAIL", nullable=false, length=64)
	private String email;
	
	@Column(name="SIGN_UP_TIME", nullable=false)
	private Date signUpTime;

	@Column(name="LAST_VISIT_TIME", nullable=true)
	private Date lastVisitTime;

	@Column(name="LOCKED_TIME", nullable=true)
	private Date lockedTime;
	
	@Column(name="ACCESS_TOKEN", length=32)
	private String accessToken;
	
    @Column(name="PERMISSION_ID",  nullable=false)
	private Long permissionId;

	public User() {
		this.signUpTime=new Date(System.currentTimeMillis());
		this.lastVisitTime=new Date(0L);
	}

	public Date getLastVisitTime() {
		return lastVisitTime;
	}

	public void setLastVisitTime(Date lastVisitTime) {
		this.lastVisitTime = lastVisitTime;
	}

	public void setAccessToken(String accessToken) {
		this.accessToken = accessToken;
	}

	public String getAccessToken() {
		return accessToken;
	}

	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long uid) {
		this.userId = uid;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	
	public Date getSignUpTime() {
		return signUpTime;
	}

	public void setSignUpTime(Date signUpTime) {
		this.signUpTime = signUpTime;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Long getPermissionId() {
		return permissionId;
	}

	public void setPermissionId(Long permissionId) {
		this.permissionId = permissionId;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public Date getLockedTime() {
		return lockedTime;
	}

	public void setLockedTime(Date lockedTime) {
		this.lockedTime = lockedTime;
	}

	public boolean checkRequiredFields(){
		return (name != null && password != null && email != null
				&& permissionId != null);
	}
	
	@Override
	public String toString() {
		return "User [userId=" + userId + ", name=" + name + ", password="
				+ password + ", Email=" + email + ", signUpTime=" + signUpTime
				+ ", lastVisitTime=" + lastVisitTime + ", lockedTime="
				+ lockedTime + ", accessToken=" + accessToken
				+ ", permissionId=" + permissionId + "]";
	}
		
}
